home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 101-125 / disk_108 / printpop / wbc.asm < prev   
Assembly Source File  |  1992-05-06  |  5KB  |  216 lines

  1. ; SPECIAL NOTE: This code module is a direct copy of the routine supplied
  2. ;               with PopCLI (Fred Fish #35) which is in turn a version of
  3. ;               the code published in the 1.1 Rom Kernel Manuals.
  4. ;
  5. ;               PopCLI is copyrighted to the Software Distillery
  6. ;
  7.     section    text,CODE
  8. *
  9. * C initial startup procedure under AmigaDOS
  10. * Requirements:
  11.  
  12.     INCLUDE    "exec/types.i"
  13.     INCLUDE "exec/alerts.i"
  14.     INCLUDE "exec/nodes.i"
  15.     INCLUDE "exec/lists.i"
  16.     INCLUDE "exec/ports.i"
  17.     INCLUDE "exec/libraries.i"
  18.     INCLUDE "exec/tasks.i"
  19.     INCLUDE "libraries/dos.i"
  20.     INCLUDE "libraries/dosextens.i"
  21.  
  22. ; some usefull macros:
  23. xlib    macro
  24.     xref    _LVO\1
  25.     endm
  26.  
  27. callsys    macro
  28.     CALLLIB    _LVO\1
  29.     endm
  30.     
  31.  
  32.     xdef    _XCEXIT            * exit(code) is standard way to leave C.
  33.     xdef    _HandlerInterface
  34.  
  35.     xref    _myhandler
  36.     xref    __main            * Name of C program to start with.
  37.     xref    _AbsExecBase
  38.     xref    _FindTask
  39.     xref    _DOSBase
  40.  
  41.     xlib    Alert
  42.     xlib    FindTask
  43.     xlib    Forbid
  44.     xlib    GetMsg
  45.     xlib    OpenLibrary
  46.     xlib    CloseLibrary
  47.     xlib    ReplyMsg
  48.     xlib    Wait
  49.     xlib    WaitPort
  50.     xlib    Open
  51.     xlib    Close
  52.     xlib    CurrentDir
  53.  
  54. start:
  55.     move.l    d0,dosCmdLen
  56.     move.l    a0,dosCmdBuf
  57.     move.l    a7,d0            ; save old stack ptr
  58.     movem.l    d1-d6/a0-a6,-(a7)
  59.     move.l    d0,a5
  60.     move.l    _AbsExecBase,a6
  61.     move.l    a6,_SysBase
  62.     move.l    a7,__StackPtr        * Save stack ptr
  63.  
  64. ;------ get the address of our task
  65.     suba.l    a1,a1
  66.     callsys    FindTask
  67.     move.l    d0,a4
  68.  
  69. ;------ are we running as a son of Workbench?
  70.     move.l    pr_CurrentDir(A4),_curdir
  71.     tst.l    pr_CLI(A4)
  72.     beq    exit2
  73.  
  74. ;=======================================================================
  75. ;====== CLI Startup Code ===============================================
  76. ;=======================================================================
  77.  
  78. fromCLI:
  79.     move.l    a5,D0        ; get top of stack
  80.     sub.l    4(a5),D0    ; compute bottom 
  81.     move.l    D0,__base    ; save for stack checking
  82. ;------    attempt to open DOS library:
  83.     lea    DOSName,A1
  84.     moveq.l    #0,D0
  85.     callsys OpenLibrary
  86.     move.l    D0,_DOSBase
  87.     beq    noDOS
  88.  
  89. ;------ find command name:
  90.     move.l    #start,a0
  91.     clr.l    -(sp)
  92.     jsr    _FindTask
  93.     addq.l    #4,sp
  94.     move.l    d0,a0
  95.     move.l    pr_CLI(a0),a0
  96.     add.l   a0,a0        ; bcpl pointer conversion
  97.     add.l   a0,a0
  98.     move.l    cli_CommandName(a0),a1
  99.     add.l   a1,a1        ; bcpl pointer conversion
  100.     add.l   a1,a1
  101.  
  102. ;------    collect parameters:
  103.     move.l    dosCmdLen,d0        ; get command line length
  104.     move.l    a1,__ProgramName
  105.     addq.l    #1,d0            ; allow for space after command    
  106.  
  107.     clr.w    -(A7)            ; set null terminator for command line
  108.     addq.l    #1,D0            ; force to even number of bytes
  109.     andi.w    #$fffe,D0        ;(round up)
  110.     sub.l    D0,A7            ; make room on stack for command line
  111.     subq.l    #2,D0
  112.     clr.w    0(A7,D0)
  113.  
  114. ;------ copy command line onto stack
  115.     move.l    dosCmdLen,d0        ; get command line length
  116.     move.l    dosCmdBuf,a0
  117.     move.l    d0,d2
  118.     subq.l    #1,d0
  119.  
  120. copy_line:
  121.     move.b    0(A0,D0.W),0(A7,D2.W)    ; copy command line to stack
  122.     subq.l    #1,d2
  123.     dbf    d0,copy_line
  124.     move.b    #' ',0(a7,d2.w)        ; add space between command and parms
  125.     subq.l    #1,d2
  126.  
  127.     move.l    A7,A1
  128.     move.l    A1,-(A7)        ; push command line address
  129.     jsr    __main                * call C entrypoint
  130.     moveq.l    #0,d0            ; set successful status
  131.     bra.l    exit2
  132.  
  133. _XCEXIT:
  134.     move.l    4(SP),d0    ; extract return code
  135. exit2:
  136.     move.l    d0,-(a7)
  137.     move.l    _SysBase,a6
  138.     move.l    _DOSBase,a1
  139.     callsys    CloseLibrary        ; close Dos library
  140.  
  141. ;------ this rts sends us back to DOS:
  142. exitToDOS:
  143.     MOVE.L    (A7)+,D0
  144.     movea.l  __StackPtr,SP        * restore stack ptr
  145.     movem.l    (a7)+,d1-d6/a0-a6
  146.     rts                * and exit
  147.  
  148. ;-----------------------------------------------------------------------
  149. noDOS:
  150.         ALERT    (AG_OpenLib!AO_DOSLib)
  151.         moveq.l    #100,d0
  152.         bra    exit2
  153.  
  154. *************************************************************************
  155. *   HandlerInterface()
  156. *
  157. *   This code is needed to convert the calling sequence performed by
  158. *   the input.task for the input stream management into something
  159. *   that a C program can understand.
  160. *
  161. *   This routine expects a pointer to an InputEvent in A0, a pointer
  162. *   to a data area in A1.  These values are transferred to the stack
  163. *   in the order that a C program would need to find them.  Since the
  164. *   actual handler is written in C, this works out fine. 
  165. *
  166. *   Author: Rob Peck, 12/1/85
  167. *
  168.  
  169. _HandlerInterface:
  170.     movem.L    A0/A1,-(A7)
  171.     jsr    _myhandler
  172.     addq.L    #8,A7
  173.     rts
  174.  
  175.     section    data,DATA
  176. ;
  177.     XDEF    _NULL,_SysBase,_LoadAddress,_console_dev,_WBenchMsg
  178.     XDEF    _curdir,__mbase,__mnext,__msize,__tsize
  179.     XDEF    __oserr,__OSERR,__FPERR,__SIGFPE,__ONERR,__ONEXIT,__ONBREAK
  180.     XDEF    __SIGINT
  181.     XDEF    _errno,_stdin,_stdout,_stderr
  182.     XDEF    __ProgramName,__StackPtr,__base
  183. ;
  184. _errno        dc.l    0
  185. _stdin        dc.l    0
  186. _stdout        dc.l    0
  187. _stderr        dc.l    0
  188. _NULL        dc.l    0        ;
  189. __base        dc.l    0        ; base of stack
  190. __mbase        dc.l    0        ; base of memory pool
  191. __mnext        dc.l    0        ; next available memory location
  192. __msize        dc.l    0        ; size of memory pool
  193. __tsize        dc.l    0        ; total size?
  194. __oserr        equ    *
  195. __OSERR        dc.l    0
  196. __FPERR        dc.l    0
  197. __SIGFPE    dc.l    0
  198. __SIGINT    dc.l    0
  199. __ONERR        dc.l    0
  200. __ONEXIT    dc.l    0
  201. __ONBREAK    dc.l    0
  202. _curdir        dc.l    0
  203. _console_dev    dc.l    0
  204. _SysBase    dc.l    0
  205. _LoadAddress    dc.l    0            ; program load address
  206. _WBenchMsg    dc.l    0
  207. __StackPtr    dc.l    0
  208. dosCmdLen    dc.l    0
  209. dosCmdBuf    dc.l    0
  210. stdin        dc.l    0
  211. __ProgramName    dc.l    0
  212. DOSName     DOSNAME
  213.  
  214.     END
  215.